package org.gcwork.fms.web;


import org.gcwork.fms.domain.Taccount;
import org.gcwork.fms.service.TaccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BaseController {

	@Autowired
	private TaccountService taccountService;

	@RequestMapping("/showMessage")
	public String sayHellow() {
		Taccount taccount = taccountService.findAccountbyId(32);
		System.out.println("web sysout:" + taccount.getId());
		return "showMessage";
	}

	// 对ajax的支出 用注解
	@RequestMapping("/getJson")
	@ResponseBody
	public Taccount sendJson(@RequestBody String str) {
		Taccount taccount = taccountService.findAccountbyId(32);
		return taccount;
	}
	
	// 对ajax的支出 用注解
	@RequestMapping("/getJson_get")
	@ResponseBody
	public Taccount sendJson_post(@RequestParam String str) {
		Taccount taccount = taccountService.findAccountbyId(32);
		return taccount;
	}
	
	
	
	
	@RequestMapping("/getWithEntity")
	//对ajax的支出 用HttpEntity/ResponseEntity
	public ResponseEntity<Taccount> sendEntity(HttpEntity<String> httpEntity)
	{
		System.out.println(httpEntity.getBody());
		Taccount taccount = taccountService.findAccountbyId(32);
		ResponseEntity<Taccount> result = new ResponseEntity<Taccount>(taccount,HttpStatus.OK);
		return result;
	}
	
	
	@RequestMapping("/getWithEntity_get")
	//对ajax的支出 用HttpEntity/ResponseEntity
	public ResponseEntity<Taccount> sendEntity_get(HttpEntity<String> httpEntity)
	{
		System.out.println(httpEntity.getBody());
		Taccount taccount = taccountService.findAccountbyId(32);
		ResponseEntity<Taccount> result = new ResponseEntity<Taccount>(taccount,HttpStatus.OK);
		return result;
	}
	
}
